﻿using AutoMapper;
using MyTask.Domain.Models;
using MyTask.Infrastructure.Context;
using System;
using System.Collections.Generic;
using System.Text;

namespace MyTask.Domain.Commands.Handlers
{
  public  class UserInfoCommandHandler
    {
        #region Private variable
        private readonly MyTaskContext _context;
        #endregion
        #region Constructor
        public UserInfoCommandHandler(MyTaskContext context)
        {
            _context = context;
        }
        #endregion
        #region Public method
        /// <summary>
        /// Register User
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public bool Register(UserInfoCommand command)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap<UserInfoCommand, UserInfo>());
            IMapper mapper = config.CreateMapper();
            UserInfo userInfo = mapper.Map<UserInfoCommand, UserInfo>(command);
            //UserInfo userInfo = new UserInfo();
            //userInfo.FirstName = command.FirstName;
            //userInfo.LastName = command.LastName;
            //userInfo.UserName = command.UserName;
            //userInfo.Email = command.Email;
            //userInfo.Password = command.Password;
            _context.UserInfos.Add(userInfo);
            var result = _context.SaveChanges() > 0;
            return result;
        } 
        #endregion
    }
}
